package com.jungle.system.repository;

import com.jungle.system.domain.CommonArea;
import com.jungle.system.domain.vo.CommonAreaSelectVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;

@Repository
public interface CommonAreaRepository extends JpaRepository<CommonArea, String>, JpaSpecificationExecutor<CommonArea> {

    CommonArea findOneByCode(String code);

//    @Query(value = "select c from CommonArea c where c.parentCode = ?1")
    List<CommonAreaSelectVo> findAllByParentCode(String code);

    @Query(value = "select c from CommonArea c where c.parentCode = ?1")
    List<CommonArea> findByParentCode(String code);


    @Query(nativeQuery = true,value = "select * from c_area   limit 10")
    List<CommonArea> findByLimit();

    List<CommonArea> findAllByCodeIn(Set<String> codes);

    @Query(value = "select c from CommonArea c where c.adCode = ?1")
    CommonArea findOneByAdCode(String adCode);
}
